(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^1).


The TRS R consists of the following rules:

minus(x, x) → 0
minus(0, x) → 0
minus(x, 0) → x
minus(s(x), s(y)) → minus(x, y)
le(0, y) → true
le(s(x), 0) → false
le(s(x), s(y)) → le(x, y)
quot(x, y) → if_quot(minus(x, y), y, le(y, 0), le(y, x))
if_quot(x, y, true, z) → divByZeroError
if_quot(x, y, false, true) → s(quot(x, y))
if_quot(x, y, false, false) → 0

Rewrite Strategy: INNERMOST

(1) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^1).


The TRS R consists of the following rules:

minus(x, x) → 0 [1]
minus(0, x) → 0 [1]
minus(x, 0) → x [1]
minus(s(x), s(y)) → minus(x, y) [1]
le(0, y) → true [1]
le(s(x), 0) → false [1]
le(s(x), s(y)) → le(x, y) [1]
quot(x, y) → if_quot(minus(x, y), y, le(y, 0), le(y, x)) [1]
if_quot(x, y, true, z) → divByZeroError [1]
if_quot(x, y, false, true) → s(quot(x, y)) [1]
if_quot(x, y, false, false) → 0 [1]

Rewrite Strategy: INNERMOST

(3) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(4) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

minus(x, x) → 0 [1]
minus(0, x) → 0 [1]
minus(x, 0) → x [1]
minus(s(x), s(y)) → minus(x, y) [1]
le(0, y) → true [1]
le(s(x), 0) → false [1]
le(s(x), s(y)) → le(x, y) [1]
quot(x, y) → if_quot(minus(x, y), y, le(y, 0), le(y, x)) [1]
if_quot(x, y, true, z) → divByZeroError [1]
if_quot(x, y, false, true) → s(quot(x, y)) [1]
if_quot(x, y, false, false) → 0 [1]

The TRS has the following type information:
minus :: 0:s:divByZeroError → 0:s:divByZeroError → 0:s:divByZeroError
0 :: 0:s:divByZeroError
s :: 0:s:divByZeroError → 0:s:divByZeroError
le :: 0:s:divByZeroError → 0:s:divByZeroError → true:false
true :: true:false
false :: true:false
quot :: 0:s:divByZeroError → 0:s:divByZeroError → 0:s:divByZeroError
if_quot :: 0:s:divByZeroError → 0:s:divByZeroError → true:false → true:false → 0:s:divByZeroError
divByZeroError :: 0:s:divByZeroError

Rewrite Strategy: INNERMOST

(5) CompletionProof (UPPER BOUND(ID) transformation)

The TRS is a completely defined constructor system, as every type has a constant constructor and the following rules were added:

minus(v0, v1) → null_minus [0]
le(v0, v1) → null_le [0]
if_quot(v0, v1, v2, v3) → null_if_quot [0]

And the following fresh constants:

null_minus, null_le, null_if_quot

(6) Obligation:

Runtime Complexity Weighted TRS where all functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

minus(x, x) → 0 [1]
minus(0, x) → 0 [1]
minus(x, 0) → x [1]
minus(s(x), s(y)) → minus(x, y) [1]
le(0, y) → true [1]
le(s(x), 0) → false [1]
le(s(x), s(y)) → le(x, y) [1]
quot(x, y) → if_quot(minus(x, y), y, le(y, 0), le(y, x)) [1]
if_quot(x, y, true, z) → divByZeroError [1]
if_quot(x, y, false, true) → s(quot(x, y)) [1]
if_quot(x, y, false, false) → 0 [1]
minus(v0, v1) → null_minus [0]
le(v0, v1) → null_le [0]
if_quot(v0, v1, v2, v3) → null_if_quot [0]

The TRS has the following type information:
minus :: 0:s:divByZeroError:null_minus:null_if_quot → 0:s:divByZeroError:null_minus:null_if_quot → 0:s:divByZeroError:null_minus:null_if_quot
0 :: 0:s:divByZeroError:null_minus:null_if_quot
s :: 0:s:divByZeroError:null_minus:null_if_quot → 0:s:divByZeroError:null_minus:null_if_quot
le :: 0:s:divByZeroError:null_minus:null_if_quot → 0:s:divByZeroError:null_minus:null_if_quot → true:false:null_le
true :: true:false:null_le
false :: true:false:null_le
quot :: 0:s:divByZeroError:null_minus:null_if_quot → 0:s:divByZeroError:null_minus:null_if_quot → 0:s:divByZeroError:null_minus:null_if_quot
if_quot :: 0:s:divByZeroError:null_minus:null_if_quot → 0:s:divByZeroError:null_minus:null_if_quot → true:false:null_le → true:false:null_le → 0:s:divByZeroError:null_minus:null_if_quot
divByZeroError :: 0:s:divByZeroError:null_minus:null_if_quot
null_minus :: 0:s:divByZeroError:null_minus:null_if_quot
null_le :: true:false:null_le
null_if_quot :: 0:s:divByZeroError:null_minus:null_if_quot

Rewrite Strategy: INNERMOST

(7) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

0 => 0
true => 2
false => 1
divByZeroError => 1
null_minus => 0
null_le => 0
null_if_quot => 0

(8) Obligation:

Complexity RNTS consisting of the following rules:

if_quot(z', z'', z1, z2) -{ 1 }→ 1 :|: z >= 0, z' = x, z1 = 2, z'' = y, z2 = z, x >= 0, y >= 0
if_quot(z', z'', z1, z2) -{ 1 }→ 0 :|: z' = x, z'' = y, z2 = 1, x >= 0, y >= 0, z1 = 1
if_quot(z', z'', z1, z2) -{ 0 }→ 0 :|: z2 = v3, v0 >= 0, z1 = v2, v1 >= 0, z'' = v1, v2 >= 0, v3 >= 0, z' = v0
if_quot(z', z'', z1, z2) -{ 1 }→ 1 + quot(x, y) :|: z2 = 2, z' = x, z'' = y, x >= 0, y >= 0, z1 = 1
le(z', z'') -{ 1 }→ le(x, y) :|: z' = 1 + x, x >= 0, y >= 0, z'' = 1 + y
le(z', z'') -{ 1 }→ 2 :|: z'' = y, y >= 0, z' = 0
le(z', z'') -{ 1 }→ 1 :|: z'' = 0, z' = 1 + x, x >= 0
le(z', z'') -{ 0 }→ 0 :|: v0 >= 0, v1 >= 0, z'' = v1, z' = v0
minus(z', z'') -{ 1 }→ x :|: z'' = 0, z' = x, x >= 0
minus(z', z'') -{ 1 }→ minus(x, y) :|: z' = 1 + x, x >= 0, y >= 0, z'' = 1 + y
minus(z', z'') -{ 1 }→ 0 :|: z' = x, x >= 0, z'' = x
minus(z', z'') -{ 1 }→ 0 :|: x >= 0, z'' = x, z' = 0
minus(z', z'') -{ 0 }→ 0 :|: v0 >= 0, v1 >= 0, z'' = v1, z' = v0
quot(z', z'') -{ 1 }→ if_quot(minus(x, y), y, le(y, 0), le(y, x)) :|: z' = x, z'' = y, x >= 0, y >= 0

Only complete derivations are relevant for the runtime complexity.

(9) CompleteCoflocoProof (EQUIVALENT transformation)

Transformed the RNTS (where only complete derivations are relevant) into cost relations for CoFloCo:

eq(start(V, V1, V13, V14),0,[minus(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V13, V14),0,[le(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V13, V14),0,[quot(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V13, V14),0,[fun(V, V1, V13, V14, Out)],[V >= 0,V1 >= 0,V13 >= 0,V14 >= 0]).
eq(minus(V, V1, Out),1,[],[Out = 0,V = V2,V2 >= 0,V1 = V2]).
eq(minus(V, V1, Out),1,[],[Out = 0,V3 >= 0,V1 = V3,V = 0]).
eq(minus(V, V1, Out),1,[],[Out = V4,V1 = 0,V = V4,V4 >= 0]).
eq(minus(V, V1, Out),1,[minus(V5, V6, Ret)],[Out = Ret,V = 1 + V5,V5 >= 0,V6 >= 0,V1 = 1 + V6]).
eq(le(V, V1, Out),1,[],[Out = 2,V1 = V7,V7 >= 0,V = 0]).
eq(le(V, V1, Out),1,[],[Out = 1,V1 = 0,V = 1 + V8,V8 >= 0]).
eq(le(V, V1, Out),1,[le(V9, V10, Ret1)],[Out = Ret1,V = 1 + V9,V9 >= 0,V10 >= 0,V1 = 1 + V10]).
eq(quot(V, V1, Out),1,[minus(V11, V12, Ret0),le(V12, 0, Ret2),le(V12, V11, Ret3),fun(Ret0, V12, Ret2, Ret3, Ret4)],[Out = Ret4,V = V11,V1 = V12,V11 >= 0,V12 >= 0]).
eq(fun(V, V1, V13, V14, Out),1,[],[Out = 1,V15 >= 0,V = V16,V13 = 2,V1 = V17,V14 = V15,V16 >= 0,V17 >= 0]).
eq(fun(V, V1, V13, V14, Out),1,[quot(V18, V19, Ret11)],[Out = 1 + Ret11,V14 = 2,V = V18,V1 = V19,V18 >= 0,V19 >= 0,V13 = 1]).
eq(fun(V, V1, V13, V14, Out),1,[],[Out = 0,V = V20,V1 = V21,V14 = 1,V20 >= 0,V21 >= 0,V13 = 1]).
eq(minus(V, V1, Out),0,[],[Out = 0,V22 >= 0,V23 >= 0,V1 = V23,V = V22]).
eq(le(V, V1, Out),0,[],[Out = 0,V24 >= 0,V25 >= 0,V1 = V25,V = V24]).
eq(fun(V, V1, V13, V14, Out),0,[],[Out = 0,V14 = V26,V27 >= 0,V13 = V28,V29 >= 0,V1 = V29,V28 >= 0,V26 >= 0,V = V27]).
input_output_vars(minus(V,V1,Out),[V,V1],[Out]).
input_output_vars(le(V,V1,Out),[V,V1],[Out]).
input_output_vars(quot(V,V1,Out),[V,V1],[Out]).
input_output_vars(fun(V,V1,V13,V14,Out),[V,V1,V13,V14],[Out]).

CoFloCo proof output:
Preprocessing Cost Relations
=====================================

#### Computed strongly connected components
0. recursive : [le/3]
1. recursive : [minus/3]
2. recursive : [fun/5,quot/3]
3. non_recursive : [start/4]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into le/3
1. SCC is partially evaluated into minus/3
2. SCC is partially evaluated into quot/3
3. SCC is partially evaluated into start/4

Control-Flow Refinement of Cost Relations
=====================================

### Specialization of cost equations le/3
* CE 21 is refined into CE [22]
* CE 19 is refined into CE [23]
* CE 18 is refined into CE [24]
* CE 20 is refined into CE [25]


### Cost equations --> "Loop" of le/3
* CEs [25] --> Loop 15
* CEs [22] --> Loop 16
* CEs [23] --> Loop 17
* CEs [24] --> Loop 18

### Ranking functions of CR le(V,V1,Out)
* RF of phase [15]: [V,V1]

#### Partial ranking functions of CR le(V,V1,Out)
* Partial RF of phase [15]:
- RF of loop [15:1]:
V
V1


### Specialization of cost equations minus/3
* CE 13 is refined into CE [26]
* CE 15 is refined into CE [27]
* CE 14 is refined into CE [28]
* CE 17 is refined into CE [29]
* CE 16 is refined into CE [30]


### Cost equations --> "Loop" of minus/3
* CEs [30] --> Loop 19
* CEs [26] --> Loop 20
* CEs [27] --> Loop 21
* CEs [28,29] --> Loop 22

### Ranking functions of CR minus(V,V1,Out)
* RF of phase [19]: [V,V1]

#### Partial ranking functions of CR minus(V,V1,Out)
* Partial RF of phase [19]:
- RF of loop [19:1]:
V
V1


### Specialization of cost equations quot/3
* CE 12 is refined into CE [31,32,33,34]
* CE 9 is refined into CE [35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53]
* CE 10 is refined into CE [54,55]
* CE 11 is refined into CE [56,57]


### Cost equations --> "Loop" of quot/3
* CEs [57] --> Loop 23
* CEs [56] --> Loop 24
* CEs [31,32,33,34] --> Loop 25
* CEs [35,36,37,38,39,40,45] --> Loop 26
* CEs [41,42,43,44,46,47,48,49,50,51,52,53,54,55] --> Loop 27

### Ranking functions of CR quot(V,V1,Out)
* RF of phase [23]: [V,V-V1+1]

#### Partial ranking functions of CR quot(V,V1,Out)
* Partial RF of phase [23]:
- RF of loop [23:1]:
V
V-V1+1


### Specialization of cost equations start/4
* CE 5 is refined into CE [58]
* CE 4 is refined into CE [59,60,61]
* CE 2 is refined into CE [62]
* CE 3 is refined into CE [63]
* CE 6 is refined into CE [64,65,66]
* CE 7 is refined into CE [67,68,69,70,71]
* CE 8 is refined into CE [72,73,74]


### Cost equations --> "Loop" of start/4
* CEs [58] --> Loop 28
* CEs [59,61] --> Loop 29
* CEs [63] --> Loop 30
* CEs [60,64,68,73] --> Loop 31
* CEs [62,65,66,67,69,70,71,72,74] --> Loop 32

### Ranking functions of CR start(V,V1,V13,V14)

#### Partial ranking functions of CR start(V,V1,V13,V14)


Computing Bounds
=====================================

#### Cost of chains of le(V,V1,Out):
* Chain [[15],18]: 1*it(15)+1
Such that:it(15) =< V

with precondition: [Out=2,V>=1,V1>=V]

* Chain [[15],17]: 1*it(15)+1
Such that:it(15) =< V1

with precondition: [Out=1,V1>=1,V>=V1+1]

* Chain [[15],16]: 1*it(15)+0
Such that:it(15) =< V1

with precondition: [Out=0,V>=1,V1>=1]

* Chain [18]: 1
with precondition: [V=0,Out=2,V1>=0]

* Chain [17]: 1
with precondition: [V1=0,Out=1,V>=1]

* Chain [16]: 0
with precondition: [Out=0,V>=0,V1>=0]


#### Cost of chains of minus(V,V1,Out):
* Chain [[19],22]: 1*it(19)+1
Such that:it(19) =< V1

with precondition: [Out=0,V>=1,V1>=1]

* Chain [[19],21]: 1*it(19)+1
Such that:it(19) =< V1

with precondition: [V=Out+V1,V1>=1,V>=V1]

* Chain [[19],20]: 1*it(19)+1
Such that:it(19) =< V

with precondition: [Out=0,V=V1,V>=1]

* Chain [22]: 1
with precondition: [Out=0,V>=0,V1>=0]

* Chain [21]: 1
with precondition: [V1=0,V=Out,V>=0]

* Chain [20]: 1
with precondition: [Out=0,V1=V,V1>=0]


#### Cost of chains of quot(V,V1,Out):
* Chain [[23],27]: 21*it(23)+18*s(5)+5
Such that:aux(12) =< V1
aux(16) =< V
it(23) =< aux(16)
s(5) =< aux(12)

with precondition: [V1>=1,Out>=1,V+1>=Out+V1]

* Chain [[23],24,27]: 8*it(23)+20*s(5)+10
Such that:aux(18) =< V1
aux(19) =< V
it(23) =< aux(19)
s(5) =< aux(18)

with precondition: [V1>=1,Out>=2,V+2>=2*V1+Out]

* Chain [27]: 18*s(5)+14*s(6)+5
Such that:aux(11) =< V
aux(12) =< V1
s(6) =< aux(11)
s(5) =< aux(12)

with precondition: [Out=0,V>=0,V1>=0]

* Chain [26]: 6*s(54)+4
Such that:aux(22) =< V
s(54) =< aux(22)

with precondition: [V1=0,Out=0,V>=0]

* Chain [25]: 4*s(66)+5
Such that:aux(24) =< V
s(66) =< aux(24)

with precondition: [V1=0,Out=1,V>=0]

* Chain [24,27]: 20*s(5)+1*s(51)+10
Such that:s(51) =< V
aux(18) =< V1
s(5) =< aux(18)

with precondition: [Out=1,V1>=1,V>=V1]


#### Cost of chains of start(V,V1,V13,V14):
* Chain [32]: 52*s(89)+80*s(90)+10
Such that:aux(28) =< V
aux(29) =< V1
s(89) =< aux(28)
s(90) =< aux(29)

with precondition: [V>=0,V1>=0]

* Chain [31]: 8*s(104)+6
Such that:aux(30) =< V
s(104) =< aux(30)

with precondition: [V1=0,V>=0]

* Chain [30]: 1
with precondition: [V13=1,V14=1,V>=0,V1>=0]

* Chain [29]: 50*s(109)+76*s(110)+11
Such that:aux(31) =< V
aux(32) =< V1
s(109) =< aux(31)
s(110) =< aux(32)

with precondition: [V13=1,V14=2,V>=0,V1>=0]

* Chain [28]: 1
with precondition: [V13=2,V>=0,V1>=0,V14>=0]


Closed-form bounds of start(V,V1,V13,V14):
-------------------------------------
* Chain [32] with precondition: [V>=0,V1>=0]
- Upper bound: 52*V+80*V1+10
- Complexity: n
* Chain [31] with precondition: [V1=0,V>=0]
- Upper bound: 8*V+6
- Complexity: n
* Chain [30] with precondition: [V13=1,V14=1,V>=0,V1>=0]
- Upper bound: 1
- Complexity: constant
* Chain [29] with precondition: [V13=1,V14=2,V>=0,V1>=0]
- Upper bound: 50*V+76*V1+11
- Complexity: n
* Chain [28] with precondition: [V13=2,V>=0,V1>=0,V14>=0]
- Upper bound: 1
- Complexity: constant

### Maximum cost of start(V,V1,V13,V14): 42*V+76*V1+4+max([2*V+4*V1,1])+ (8*V+5)+1
Asymptotic class: n
* Total analysis performed in 506 ms.

(10) BOUNDS(1, n^1)